//
//  AlipayStore.m
//  NewPro
//
//  Created by RYX on 2018/10/31.
//  Copyright © 2018年 何荧红. All rights reserved.
//

#import "AlipayStore.h"

@implementation AlipayStore


#pragma mark - 支付宝支付
- (void)alipayWithId:(NSString *)uid Success:(void(^)(NSString *sign))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/pay/aliPay",IP];
    
    NSDictionary *dic = @{
                          @"id":uid
                          };
    
    NSLog(@"支付宝=======%@",url);
    [HttpTool postUrlWithString:url parameters:dic success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        
        if (error == nil) {
            
            NSString *str = responseObject[@"data"][@"sign"];
            success(str);
        }else{
            
            failure(error);
        }
    } failure:^(NSError *error) {
       
        failure(error);
    }];
}

#pragma mark - 微信支付
- (void)payWithWeixin:(NSString *)uid Success:(void(^)(NSDictionary *res))success Failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/api/wx/wxPay",IP];
    NSDictionary *dic = @{
                          @"id":uid
                          };
    [HttpTool postUrlWithString:url parameters:dic success:^(id responseObject) {
        NSError *error = [HttpTool inspectError:responseObject];
        if (error == nil) {
            NSDictionary *str = responseObject[@"data"];
            success(str);
        }else{
            failure(error);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

#pragma mark 获取余额
- (void)GetYuePayWithPrams:(NSDictionary *)prams Success:(void(^)(NSDictionary *res))success Failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/api/custom/account",IP];
    [HttpTool getUrlWithString:url parameters:prams success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        if (error == nil) {
            success(responseObject);
        }else{
            failure(error);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

#pragma mark 余额支付接口
- (void)YuePayWithSecret:(NSString *)secret andOrderId:(NSString *)orderId Success:(void(^)(NSString *Msg))success Failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/api/balance/pay",IP];
    NSDictionary *prams = @{
                            @"secret":secret,
                            @"orderId":orderId
                            };
    [HttpTool postUrlWithString:url parameters:prams success:^(id responseObject) {
        NSError *error = [HttpTool inspectError:responseObject];
        if (error == nil) {
            success(responseObject[@"msg"]);
        }else{
            failure(error);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}


@end
